home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Applications / QIF Creator / D&S to QIF.c < prev    next >
C/C++ Source or Header  |  1993-09-23  |  11KB  |  384 lines

  1. #include <stdio.h>
  2. #define MAX_FILENAME    34
  3. #define MAX_LINEWIDTH    512
  4.  
  5. char transdate[10];
  6. char cknumber[8];
  7. char payToFrom[60];
  8. char account[60], deposit[20], withdrawal[20];
  9. char Cleared[5], flag[8], description[60];
  10.  
  11. char account1[60], deposit1[20], withdrawal1[20];
  12. char Cleared1[5], flag1[8], description1[60];
  13. char account2[60], deposit2[20], withdrawal2[20];
  14. char Cleared2[5], flag2[8], description2[60];
  15. char account3[60], deposit3[20], withdrawal3[20];
  16. char Cleared3[5], flag3[8], description3[60];
  17. char account4[60], deposit4[20], withdrawal4[20];
  18. char Cleared4[5], flag4[8], description4[60];
  19. char account5[60], deposit5[20], withdrawal5[20];
  20. char Cleared5[5], flag5[8], description5[60];
  21. char account6[60], deposit6[20], withdrawal6[20];
  22. char Cleared6[5], flag6[8], description6[60];
  23. char account7[60], deposit7[20], withdrawal7[20];
  24. char Cleared7[5], flag7[8], description7[60];
  25. char account8[60], deposit8[20], withdrawal8[20];
  26. char Cleared8[5], flag8[8], description8[60];
  27. char account9[60], deposit9[20], withdrawal9[20];
  28. char Cleared9[5], flag9[8], description9[60];
  29. char account10[60], deposit10[20], withdrawal10[20];
  30. char Cleared10[5], flag10[8], description10[60];
  31. FILE *outfptr;
  32. main()
  33. {
  34.     FILE *infptr;
  35.     char infname[MAX_FILENAME], Htype[20];
  36.     char outfname[MAX_FILENAME];
  37.     char curr_line [MAX_LINEWIDTH];
  38.     char procedure_line [MAX_LINEWIDTH];
  39.     char teststr[MAX_LINEWIDTH];
  40.     
  41.  
  42.     char c;
  43.     int  count,i;
  44.     
  45.     i=0;
  46.     printf("File Name? ");
  47.     gets(infname);
  48.     
  49.     printf("Enter HEADER TYPE (Bank, Cash, CCard, Oth A, Oth L, Invest...): ");
  50.     gets(Htype);
  51.     printf("\n\n\n");
  52.  
  53.     infptr = fopen(infname,"r");
  54.     
  55.     if (!infptr)
  56.     {
  57.         printf("\n\nError opening the file: %s\n",infname);
  58.         printf("\n(Please hit the RETURN key to continue)");
  59.  
  60.         exit(0);
  61.     }
  62.     else
  63.     {
  64.         strcpy(outfname,infname);
  65.         strcat(outfname,".QIF");
  66.         outfptr = fopen(outfname,"w");
  67.         
  68.         fprintf(outfptr,"!Type:%s\n",Htype);
  69.         while (!feof(infptr))
  70.         {
  71.             fgets(curr_line,MAX_LINEWIDTH,infptr);
  72.             getfield(teststr,curr_line,1);
  73.             if (isdate(teststr))
  74.             {
  75.                 count = 0;
  76.                 i=i+1;
  77.                 dumpit();
  78.                 printf("Number of Transactions Converted: %i\r",i);
  79.                 account1[0]=account2[0]=account3[0]=account4[0]=account5[0]=account6[0]=account7[0]=account8[0]=account9[0]=account10[0]=0;
  80.                 deposit1[0]=deposit2[0]=deposit3[0]=deposit4[0]=deposit5[0]=deposit6[0]=deposit7[0]=deposit8[0]=deposit9[0]=deposit10[0]=0;
  81.                 withdrawal1[0]=withdrawal2[0]=withdrawal3[0]=withdrawal4[0]=withdrawal5[0]=withdrawal6[0]=withdrawal7[0]=withdrawal8[0]=withdrawal9[0]=withdrawal10[0]=0;
  82.                 Cleared1[0]=Cleared2[0]=Cleared3[0]=Cleared4[0]=Cleared5[0]=Cleared6[0]=Cleared7[0]=Cleared8[0]=Cleared9[0]=Cleared10[0]=0;
  83.                 flag1[0]=flag2[0]=flag3[0]=flag4[0]=flag5[0]=flag6[0]=flag7[0]=flag8[0]=flag9[0]=flag10[0]=0;
  84.                 description1[0]=description2[0]=description3[0]=description4[0]=description5[0]=description6[0]=description7[0]=description8[0]=description9[0]=description10[0]=0;
  85.  
  86.                 strcpy(transdate,teststr);
  87.                 getfield(cknumber,curr_line,2);
  88.                 getfield(payToFrom,curr_line,3);
  89.                 getfield(account,curr_line,4);
  90.                 getfield(deposit,curr_line,5);
  91.                 getfield(withdrawal,curr_line,6);
  92.                 getfield(Cleared,curr_line,7);
  93.                 getfield(flag,curr_line,8);
  94.                 getfield(description,curr_line,11);
  95.             }
  96.             else
  97.             {
  98.                 count= count + 1;
  99.                 if (count == 1)
  100.                 {
  101.                     getfield(account1,curr_line,4);
  102.                     getfield(deposit1,curr_line,5);
  103.                     getfield(withdrawal1,curr_line,6);
  104.                     getfield(Cleared1,curr_line,7);
  105.                     getfield(flag1,curr_line,8);
  106.                     getfield(description1,curr_line,11);
  107.                 }
  108.                 else if (count == 2)
  109.                 {
  110.                     getfield(account2,curr_line,4);
  111.                     getfield(deposit2,curr_line,5);
  112.                     getfield(withdrawal2,curr_line,6);
  113.                     getfield(Cleared2,curr_line,7);
  114.                     getfield(flag2,curr_line,8);
  115.                     getfield(description2,curr_line,11);
  116.                 }
  117.                 else if (count == 3)
  118.                 {
  119.                     getfield(account3,curr_line,4);
  120.                     getfield(deposit3,curr_line,5);
  121.                     getfield(withdrawal3,curr_line,6);
  122.                     getfield(Cleared3,curr_line,7);
  123.                     getfield(flag3,curr_line,8);
  124.                     getfield(description3,curr_line,11);
  125.                 }
  126.                 else if (count == 4)
  127.                 {
  128.                     getfield(account4,curr_line,4);
  129.                     getfield(deposit4,curr_line,5);
  130.                     getfield(withdrawal4,curr_line,6);
  131.                     getfield(Cleared4,curr_line,7);
  132.                     getfield(flag4,curr_line,8);
  133.                     getfield(description4,curr_line,11);
  134.                 }
  135.                 else if (count == 5)
  136.                 {
  137.                     getfield(account5,curr_line,4);
  138.                     getfield(deposit5,curr_line,5);
  139.                     getfield(withdrawal5,curr_line,6);
  140.                     getfield(Cleared5,curr_line,7);
  141.                     getfield(flag5,curr_line,8);
  142.                     getfield(description5,curr_line,11);
  143.                 }
  144.                 else if (count == 6)
  145.                 {
  146.                     getfield(account6,curr_line,4);
  147.                     getfield(deposit6,curr_line,5);
  148.                     getfield(withdrawal6,curr_line,6);
  149.                     getfield(Cleared6,curr_line,7);
  150.                     getfield(flag6,curr_line,8);
  151.                     getfield(description6,curr_line,11);
  152.                 }
  153.                 else if (count == 7)
  154.                 {
  155.                     getfield(account7,curr_line,4);
  156.                     getfield(deposit7,curr_line,5);
  157.                     getfield(withdrawal7,curr_line,6);
  158.                     getfield(Cleared7,curr_line,7);
  159.                     getfield(flag7,curr_line,8);
  160.                     getfield(description7,curr_line,11);
  161.                 }
  162.                 else if (count == 8)
  163.                 {
  164.                     getfield(account8,curr_line,4);
  165.                     getfield(deposit8,curr_line,5);
  166.                     getfield(withdrawal8,curr_line,6);
  167.                     getfield(Cleared8,curr_line,7);
  168.                     getfield(flag8,curr_line,8);
  169.                     getfield(description8,curr_line,11);
  170.                 }
  171.                 else if (count == 9)
  172.                 {
  173.                     getfield(account9,curr_line,4);
  174.                     getfield(deposit9,curr_line,5);
  175.                     getfield(withdrawal9,curr_line,6);
  176.                     getfield(Cleared9,curr_line,7);
  177.                     getfield(flag9,curr_line,8);
  178.                     getfield(description9,curr_line,11);
  179.                 }
  180.                 else if (count == 10)
  181.                 {
  182.                     getfield(account10,curr_line,4);
  183.                     getfield(deposit10,curr_line,5);
  184.                     getfield(withdrawal10,curr_line,6);
  185.                     getfield(Cleared10,curr_line,7);
  186.                     getfield(flag10,curr_line,8);
  187.                     getfield(description10,curr_line,11);
  188.                 }
  189.             }
  190.         }
  191.         dumpit();
  192.     }
  193.     fclose(infptr);
  194.     fclose(outfptr);
  195.     printf("\n\nCONVERSION SUCCESSFULLY COMPLETED!!!\n\n(Please hit the RETURN key to continue)");
  196. }
  197.  
  198. dumpit()
  199. {
  200.  
  201.     fprintf(outfptr,"D%s\n",transdate);
  202.     if (deposit[0] != 0)
  203.         fprintf(outfptr,"T%s\n",deposit);
  204.     if (withdrawal[0] != 0)
  205.         fprintf(outfptr,"T-%s\n",withdrawal);
  206.     if (Cleared[0] != 0)
  207.         fprintf(outfptr,"C*\n");        
  208.     if (cknumber[0] != 0)
  209.         fprintf(outfptr,"N%s\n",cknumber);
  210.     fprintf(outfptr,"P%s\n",payToFrom);
  211.     if (description[0] != 0)
  212.         fprintf(outfptr,"M%s\n",description);
  213.     fprintf(outfptr,"L%s\n",account1);
  214.     if (account2[0] !=0)
  215.     {
  216.         fprintf(outfptr,"S%s\n",account1);
  217.         fprintf(outfptr,"E%s\n",description1);
  218.         if (deposit1[0] != 0)
  219.             fprintf(outfptr,"$-%s\n",deposit1);
  220.         if (withdrawal1[0] != 0)
  221.             fprintf(outfptr,"$%s\n",withdrawal1);
  222.             
  223.         fprintf(outfptr,"S%s\n",account2);
  224.         fprintf(outfptr,"E%s\n",description2);
  225.         if (deposit2[0] != 0)
  226.             fprintf(outfptr,"$-%s\n",deposit2);
  227.         if (withdrawal2[0] != 0)
  228.             fprintf(outfptr,"$%s\n",withdrawal2);
  229.  
  230.     }
  231.     if (account3[0] !=0)
  232.     {
  233.         fprintf(outfptr,"S%s\n",account3);
  234.         fprintf(outfptr,"E%s\n",description3);
  235.         if (deposit3[0] != 0)
  236.             fprintf(outfptr,"$-%s\n",deposit3);
  237.         if (withdrawal3[0] != 0)
  238.             fprintf(outfptr,"$%s\n",withdrawal3);
  239.     }
  240.     if (account4[0] !=0)
  241.     {
  242.         fprintf(outfptr,"S%s\n",account4);
  243.         fprintf(outfptr,"E%s\n",description4);
  244.         if (deposit4[0] != 0)
  245.             fprintf(outfptr,"$-%s\n",deposit4);
  246.         if (withdrawal4[0] != 0)
  247.             fprintf(outfptr,"$%s\n",withdrawal4);
  248.     }
  249.     if (account5[0] !=0)
  250.     {
  251.         fprintf(outfptr,"S%s\n",account5);
  252.         fprintf(outfptr,"E%s\n",description5);
  253.         if (deposit5[0] != 0)
  254.             fprintf(outfptr,"$-%s\n",deposit5);
  255.         if (withdrawal5[0] != 0)
  256.             fprintf(outfptr,"$%s\n",withdrawal5);
  257.     }
  258.     if (account6[0] !=0)
  259.     {
  260.         fprintf(outfptr,"S%s\n",account6);
  261.         fprintf(outfptr,"E%s\n",description6);
  262.         if (deposit6[0] != 0)
  263.             fprintf(outfptr,"$-%s\n",deposit6);
  264.         if (withdrawal6[0] != 0)
  265.             fprintf(outfptr,"$%s\n",withdrawal6);
  266.     }
  267.     if (account7[0] !=0)
  268.     {
  269.         fprintf(outfptr,"S%s\n",account7);
  270.         fprintf(outfptr,"E%s\n",description7);
  271.         if (deposit7[0] != 0)
  272.             fprintf(outfptr,"$-%s\n",deposit7);
  273.         if (withdrawal7[0] != 0)
  274.             fprintf(outfptr,"$%s\n",withdrawal7);
  275.     }
  276.     if (account8[0] !=0)
  277.     {
  278.         fprintf(outfptr,"S%s\n",account8);
  279.         fprintf(outfptr,"E%s\n",description8);
  280.         if (deposit8[0] != 0)
  281.             fprintf(outfptr,"$-%s\n",deposit8);
  282.         if (withdrawal8[0] != 0)
  283.             fprintf(outfptr,"$%s\n",withdrawal8);
  284.     }
  285.     if (account9[0] !=0)
  286.     {
  287.         fprintf(outfptr,"S%s\n",account9);
  288.         fprintf(outfptr,"E%s\n",description9);
  289.         if (deposit9[0] != 0)
  290.             fprintf(outfptr,"$-%s\n",deposit9);
  291.         if (withdrawal9[0] != 0)
  292.             fprintf(outfptr,"$%s\n",withdrawal9);
  293.     }
  294.     if (account10[0] !=0)
  295.     {
  296.         fprintf(outfptr,"S%s\n",account10);
  297.         fprintf(outfptr,"E%s\n",description10);
  298.         if (deposit10[0] != 0)
  299.             fprintf(outfptr,"$-%s\n",deposit10);
  300.         if (withdrawal10[0] != 0)
  301.             fprintf(outfptr,"$%s\n",withdrawal10);
  302.     }
  303.  
  304.     fprintf(outfptr,"^\n");
  305.  
  306.  
  307.  
  308.  
  309.  
  310. /*    printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",transdate,cknumber,payToFrom,account,deposit,withdrawal,Cleared,flag,description);
  311.     if (account1[0] != 0)
  312.         printf("%s\t%s\t%s\t%s\t%s\t%s\n",account1,deposit1,withdrawal1,Cleared1,flag1,description1);
  313.     if (account2[0] != 0)
  314.         printf("%s\t%s\t%s\t%s\t%s\t%s\n",account2,deposit2,withdrawal2,Cleared2,flag2,description2);
  315.     if (account3[0] != 0)
  316.         printf("%s\t%s\t%s\t%s\t%s\t%s\n",account3,deposit3,withdrawal3,Cleared3,flag3,description3);
  317.     if (account4[0] != 0)
  318.         printf("%s\t%s\t%s\t%s\t%s\t%s\n",account4,deposit4,withdrawal4,Cleared4,flag4,description4);
  319.     if (account5[0] != 0)
  320.         printf("%s\t%s\t%s\t%s\t%s\t%s\n",account5,deposit5,withdrawal5,Cleared5,flag5,description5);
  321.     if (account6[0] != 0)
  322.         printf("%s\t%s\t%s\t%s\t%s\t%s\n",account6,deposit6,withdrawal6,Cleared6,flag6,description6);
  323.     if (account7[0] != 0)
  324.         printf("%s\t%s\t%s\t%s\t%s\t%s\n",account7,deposit7,withdrawal7,Cleared7,flag7,description7);
  325.     if (account8[0] != 0)
  326.         printf("%s\t%s\t%s\t%s\t%s\t%s\n",account8,deposit8,withdrawal8,Cleared8,flag8,description8);
  327.     if (account9[0] != 0)
  328.         printf("%s\t%s\t%s\t%s\t%s\t%s\n",account9,deposit9,withdrawal9,Cleared9,flag9,description9);
  329.     if (account10[0] != 0)
  330.         printf("%s\t%s\t%s\t%s\t%s\t%s\n",account10,deposit10,withdrawal10,Cleared10,flag10,description10);
  331. */
  332. }
  333.  
  334. /* extracts the fieldno'th field string (s1) which is separated from other strings by */
  335. /* a TAB. This string is taken from a string (s2) */
  336. getfield(s1,s2,fieldno)
  337. char *s1,*s2;
  338. int fieldno;
  339. {
  340.     int count;
  341.     
  342.     count = 0;
  343.     fieldno = fieldno -1;
  344.     
  345.     if (fieldno == 0)
  346.     {
  347.         while (*s2 != 0 && *s2 != '\t')
  348.             *s1++ = *s2++;
  349.         *s1 = 0;
  350.     }
  351.     else
  352.     {
  353.         while (*s2 != 0 && count != fieldno)
  354.         {
  355.             if (*s2++ == '\t')
  356.                 count = count + 1;
  357.         }
  358.     
  359.         while (*s2 != 0 && *s2 != '\t')
  360.             *s1++ = *s2++;
  361.         *s1 = 0;
  362.     }
  363. }
  364.  
  365. /* checks to see if str is a date. Really only checks to see if there are 2 '/' in the */
  366. /* str. very crude! */
  367. isdate(str)
  368. char *str;
  369. {
  370.  
  371.     int count;
  372.     
  373.     count = 0;
  374.     while (*str)
  375.     {
  376.         if (*str++ == '/')
  377.             count = count +1;
  378.     }
  379.     if (count == 0)
  380.         return(0);
  381.     return(1);
  382. }
  383.  
  384.